package team526.controller;

import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import team526.dao.AdminDao;
import team526.dao.VideoDao;
import team526.entity.Admin;
import team526.entity.Admin_Video;
import team526.entity.Video;
import team526.service.AdminService;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * #Date 2021/10/28 - 19:54
 *
 * @author 王铭 20181620310021
 */
@Api(tags = "管理员接口")
@RestController
@RequestMapping("admin")
@CrossOrigin(origins = {"http://localhost:8080","http://192.168.31.212:8080","http://127.0.0.1:8080","http://video.team526:8080"}, allowCredentials = "true")
public class AdminController {

    @Autowired
    AdminDao adminDao;

    @Autowired
    VideoDao videoDao;

    @Autowired
    AdminService adminService;

    @GetMapping("login")
    public Admin login(String username,String pwd,@ApiIgnore HttpSession session){
        Admin admin=adminDao.login(username,pwd);
        if (admin!=null){
            session.setAttribute("currentAdminId",admin.getUadmin_id());
            session.setAttribute("currentAdmin",admin);
            return admin;
        }
        session.invalidate();
        return null;
    }
    @GetMapping("logout")
    public Boolean logout(@ApiIgnore HttpSession session) {
        session.invalidate();
        return true;
    }
    @GetMapping("check_video")
    public Integer checkVideo(Integer videoid, Boolean pass, @RequestParam(required = false) String reason, @RequestAttribute@ApiIgnore Integer uadmin_id){
        return adminService.check(videoid,pass,reason,uadmin_id);
    }
    @GetMapping("get_checked_result")
    public List<Admin_Video> getCheckedResult(@RequestAttribute@ApiIgnore Integer uadmin_id){
        return adminDao.getChecked(uadmin_id);
    }

    @GetMapping("get_unchecked_video")
    public List<Video> getUncheckedVideo(@RequestAttribute@ApiIgnore Integer uadmin_id){
        return adminDao.getUnchecked(uadmin_id);

    }
    @GetMapping("current")
    public Admin getCurrent(@RequestAttribute Admin uadmin){
        return uadmin;
    }

    @GetMapping("getvideo/{videoid}")
    public Video getvideo(@PathVariable Integer videoid){
        return videoDao.getVideoById(videoid);
    }
}
